<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Exposure_orderModel
 *
 * @author wml
 */

namespace Admin\Model;

use Think\Model;

class ExposurePackageModel extends Model {
    /* 自动验证规则 */

    protected $_validate = array(
        array('package_name', "require", '请输入套餐标题', self::MUST_VALIDATE, 'regex'),
   //    array('package_content', "require", '请输入套餐内容', self::MUST_VALIDATE, 'regex'),
        array('exposure_time', "require", '请输入曝光时间', self::MUST_VALIDATE, 'regex'),
        array('exposure_num', "require", '请输入曝光次数', self::MUST_VALIDATE, 'regex'),
        array('price', "require", '请输入套餐价格', self::MUST_VALIDATE, 'regex'),
    );

    public function editData($data) {
        if (empty($data)) {
            return false;
        }
         if (!$this->create($data)) {
                $this->error = $this->getError();
                return false;
            }
        /* 添加或新增行为 */
        if (empty($data['id'])) { //新增数据       
            $data["add_time"] = date("Y-m-d H:i:s");
            $id = $this->add(); //添加行为
            if (!$id) {
                $this->error = "添加失败，请重试";
                return false;
            }
        } else { //更新数据
            $status = $this->save(); //更新基础内容
            if (false === $status) {
                $this->error = "修改失败，请重试";
                return false;
            }
        }
        return $data;
    }
    
    public function deleteData($map) {
        $result = $this->where($map)->delete();
        return $result;
    }

    /*
     * 根据ID查询详细信息
     * @author  csb
     */

    public function getDataById($map, $field = "*") {
        $relust = $this->field($field)->where($map)->find();
        return $relust;
    }

    /*
     * 
     * 获取云曝光的列表
     * @author  csb
     */

    public function getExposurePackage($field = "*",$order="id desc") {
    
        $datalist = S("ExposurePackage");
        if ($datalist) {
            return $datalist;
        } else {
            $datalist = $this->field($field)->order($order)->select();
            S("ExposurePackage", $datalist);
            return $datalist;
        }
    }

    /*
     * 
     * 获取云曝光套餐的列表
     * @author  csb
     */
    public function exposurePackageList($map = "1=1", $field = "*") {
        $datalist = getPages($this, $map, "id desc", C('PAGESIZE'), null, $field);
        return $datalist;
    }

}

?>
